package stack;

import static stack.calculate.isOper;
import static stack.calculate.priority;

/**
 * 从左向右扫描，将3，4压入栈堆；
 * 遇到运算符，因此弹出4和3
 */
public class calBL {
    public static void main(String[] args) {


        String expresion = "34+5*6-";//（3+4）*5-6

        //创建两个栈，数栈 符号栈
        ArrayStack numStack = new ArrayStack(10);
        ArrayStack operStack = new ArrayStack(10);

        //定义需要的相关变量
        int index = 0;

        char ch1 = expresion.charAt(0);
        int num1 = 0;
        int num2 = 0;
        int oper = 0;
        int res = 0;
        char ch = ' ';
        String keepNum = "";
        //while
        while (true) {
            ch = expresion.substring(index, index + 1).charAt(0);//substring 返回String charAt返回char
            //判断ch是什么 ，然后做相应处理
            if (isOper(ch)) {
              num1=  numStack.pop();
                num2=  numStack.pop();

                oper=ch;
              res=  calculate.cal(num1,num2,oper);
              numStack.push(res);
                index++;
                if (index >= expresion.length()) {
                    break;
                }
            } else {
                numStack.push(Integer.parseInt(String.valueOf(ch)));
                index++;
            }
        }

        int res2 = numStack.pop();
        System.out.println(res2);

    }
}
